package aishua.com.mytestapplist.mimaxiang;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


import java.util.ArrayList;

import aishua.com.mytestapplist.MyApplication;
import aishua.com.mytestapplist.R;

/**
 * Created by Administrator on 2017/3/15 0015.
 */
public class DragAdapter extends BaseAdapter {

    protected Context mContext;
    protected ArrayList<UserInfo> mlist;

    public DragAdapter(Context mContext, ArrayList<UserInfo> mlist) {
        this.mContext = mContext;
        this.mlist = mlist;
    }

    public int getCount() {
        if (this.mlist != null) {
            return this.mlist.size();
        }
        return 0;
    }

    public UserInfo getItem(int position) {
        return this.mlist.get(position);
    }

    public long getItemId(int position) {
        return 0;
    }

    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView == null) {
            vh = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.activity_item, null);
            vh.tv = (TextView) convertView.findViewById(R.id.item_text);
            vh.image = (ImageView) convertView.findViewById(R.id.item_image);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        vh.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!MyApplication.isDraw) {
                    Toast.makeText(mContext,"详情正在开发，请稍后",Toast.LENGTH_LONG).show();
                }
            }
        });
        vh.tv.setText((getItem(position)).getMsg());
        return convertView;
    }

    private class ViewHolder {
        TextView tv;
        ImageView image;
    }
}